<!--
 * @Description:过年时间倒计时
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-13 17:58:40
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>过年时间倒计时</title>
	<style>

	</style>
	<script>
		window.onload = function () {
			var timer = null;
			var btn = document.getElementById("demo")
			var mk = document.getElementById("mk")
			var endTime = new Date("2020/1/24 23:59:59");
			clearInterval(timer)
			timer = setInterval(clock, 1000)
			function clock() {
				var nowTime = new Date();
				var second = parseInt((endTime.getTime() - nowTime.getTime()) / 1000)
				// console.log(second)
				var y = parseInt(second / 3600 / 24 / 30)
				var d = parseInt(second / 3600 / 24)
				var h = parseInt(second / 3600 % 24)
				var m = parseInt(second / 60 % 60)
				var s = parseInt(second % 60)
				y < 10 ? y = "0" + y : y
				d < 10 ? d = "0" + d : d
				h < 10 ? h = "0" + h : h
				m < 10 ? m = "0" + m : m
				s < 10 ? s = "0" + s : s
				let sm = `现在离过年还剩下
				        ${y}月
								${d}天
								${h}小时
								${m}分钟
								${s}秒
								`
				mk.innerHTML = sm
				// console.log("xiaojia3", s)
			}
			// console.log("xiaojia", endTime)

		}
	</script>
</head>

<body>
	<div id="demo"></div>
	<h1 id="mk"></h1>
</body>

</html>